<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>编辑配置·思通投研·让数据驱动投资价值!</title>
	<link href="${pageContext.request.contextPath }/img/webLogoIcon.png" rel="shortcut icon">
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/custom.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/datatables.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/datepicker3.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/toastr.min.css" rel="stylesheet" />
	<link href="${pageContext.request.contextPath }/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    
    <style>
		.left{
		    float:left;
		    width:33%;
		}
		.form-horizontal{
			width: 95%;
		}
		.form-control {
			display: inline;
		}
		.col-sm-2{
			height: 50px;
		}
	</style>
</head>

<body>

    <div id="wrapper">

        <nav class="navbar-default navbar-static-side" role="navigation">
            <%request.setAttribute("LEFT", "websitelist");%>
			<%@include file="left-factory.jsp"%>
        </nav>

        <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom">
        <jsp:include page="head-factory.jsp" flush="true" /> 
        </div>
            <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>编辑配置</h2>
                </div>
            </div>
        <div class="wrapper wrapper-content">
            <div class="ibox-content">
            	<button class="btn btn-white pull-right" onclick="window.location.href = '${pageContext.request.contextPath}/searchenging/configlist?pageNum=${pageNum}'" type="button">返回</button>
                <div class="table-responsive" style="margin-top: 5%;">
                	
                    <div class="panel-body">
                           <fieldset class="form-horizontal">
                               <c:forEach items="${list }" var="lis">
                               
                               <div class="form-group"><label class="col-sm-2 control-label">配置名:</label>
                                   <div class="col-sm-10"><input type="text" class="form-control" id="config_name" style="width: 88%;" value="${lis.config_name }" placeholder="配置名"><a style="color:red;font-size:30px">*</a></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">搜索页链接:</label>
                                   <div class="col-sm-10"><input type="text" class="form-control" id="url" style="width: 88%;" value="${lis.url }" placeholder="搜索页链接"><a style="color:red;font-size:30px">*</a></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">搜索链接配置:</label>
                                   <div class="col-sm-10"><input type="text" class="form-control" id="search_rule" style="width: 88%;" value="${lis.search_rule }" placeholder="搜索链接配置"><a style="color:red;font-size:30px">*</a></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">url提取规则:</label>
                                   <div class="col-sm-10"><input type="text" class="form-control" id="url_config" style="width: 88%;" value="${lis.url_config }" placeholder="url提取规则"><a style="color:red;font-size:30px">*</a></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">标题提取规则:</label>
                                   <div class="col-sm-10"><input type="text" class="form-control" id="title_config" style="width: 88%;" value="${lis.title_config }" placeholder="标题提取规则"></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">日期提取规则:</label>
                                   <div class="col-sm-10"><input type="text" class="form-control" id="date_config" style="width: 88%;" value="${lis.date_config }" placeholder="日期提取规则"></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">正文提取规则:</label>
                                   <div class="col-sm-10"><input type="text" class="form-control" id="text_config" style="width: 88%;" value="${lis.text_config }" placeholder="正文提取规则"></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">正文类型:</label>
                                   <div class="col-sm-10"><input type="text" class="form-control" id="text_config_type" style="width: 88%;" value="${lis.text_config_type }" placeholder="正文类型"></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">提取方式:</label>
                                   <div class="col-sm-10">
                                   <select class="form-control" style="display: inline;width: 35%;"
											id="spider_type">
											<c:if test="${lis.spider_type==1}">
												<option value="1" selected="selected">智能提取</option>
												<option value="2">手动抓取</option>
											</c:if>
											<c:if test="${lis.spider_type==2}">
												<option value="1">智能提取</option>
												<option value="2" selected="selected">手动抓取</option>
											</c:if>
                                   </select><a style="color:red;font-size:30px">*</a>
                               </div>
                               </div>
                               
                               <div class="form-group"><label class="col-sm-2 control-label">请求方式:</label>
                                   <div class="col-sm-10">
                                   <select class="form-control" style="display: inline;width: 35%;"
											id="request_type">
											<c:if test="${lis.request_type==1}">
												<option value="1" selected="selected">get</option>
												<option value="2">post</option>
											</c:if>
											<c:if test="${lis.request_type==2}">
												<option value="1">get</option>
												<option value="2" selected="selected">post</option>
											</c:if>
                                   </select><a style="color:red;font-size:30px">*</a>
                               </div>
                               </div>
                               
                               
                               
                               <div class="form-group"><label class="col-sm-2 control-label">任务对应网站id:</label>
                                   <div class="col-sm-10">
                                   <input list="website_id" id="ipt" value="${lis.website_id}"><a style="color:red;font-size:30px">*</a><p>当前网站:${lis.website_name}</p>
                                  
									<datalist id="website_id">
											
											<c:forEach items="${str }" var="list">
											<option value="${list.id }">${list.website_name }</option>
											</c:forEach>
									</datalist>
                               </div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">是否站内搜索:</label>
                                   <div class="col-sm-10">
                                   <select class="form-control" style="display: inline;width: 35%;"
											id="isOnSite">
											<c:if test="${lis.isOnSite==1}">
												<option value="1" selected="selected">是</option>
												<option value="2">否</option>
											</c:if>
											<c:if test="${lis.isOnSite==2}">
												<option value="2" selected="selected">否</option>
												<option value="1">是</option>
											</c:if>
                                   </select><a style="color:red;font-size:30px">*</a>
                               </div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">请求配置:</label>
                                   <div class="col-sm-10"><textarea class="form-control" id="request_config" style="width: 88%;height:200px" placeholder="请求配置(cookie等参数)">${lis.request_config }</textarea></div>
                               </div>
                               <div class="form-group"><label class="col-sm-2 control-label">返回类型:</label>
                                   <div class="col-sm-10">
                                   <select class="form-control" style="display: inline;width: 35%;"
											id="result_type">
											<c:if test="${lis.result_type==1}">
												<option value="1" selected="selected">html</option>
												<option value="2">json</option>
												<option value="3">json-callback</option>
											</c:if>
											<c:if test="${lis.result_type==2}">
												<option value="1">html</option>
												<option value="2" selected="selected">json</option>
												<option value="3">json-callback</option>
											</c:if>
											<c:if test="${lis.result_type==3}">
												<option value="1">html</option>
												<option value="2">json</option>
												<option value="3" selected="selected">json-callback</option>
											</c:if>
                                   </select><a style="color:red;font-size:30px">*</a>
                               </div>
                               </div>
                               </c:forEach>
                           </fieldset>
                           <button class="btn btn-primary"style="margin-left: 45%;margin-top: 2%;" onclick="addWebSite()" type="button">确定编辑</button>
                       </div>
                   </div>
                </div>
            </div>
			<jsp:include page="footer.jsp" flush="true" />
        </div>
        </div>



    <!-- Mainly scripts -->
    <script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/jquery.metisMenu.js"></script>
    <script src="${pageContext.request.contextPath }/js/jquery.slimscroll.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/jquery.jeditable.js"></script>
    <script src="${pageContext.request.contextPath }/js/datatables.min.js"></script>
    
    <!-- Peity -->
    <script src="${pageContext.request.contextPath }/js/jquery.peity.min.js"></script>

    <!-- Custom and plugin javascript -->
    <script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
    <script src="${pageContext.request.contextPath }/js/pace.min.js"></script>

    <!-- Peity -->
    <script src="${pageContext.request.contextPath }/js/peity-demo.js"></script>
	<!-- toastr -->
	<script src="${pageContext.request.contextPath }/js/plugins/toastr/toastr.min.js"></script>
	<!-- Sweet alert -->
	<script src="${pageContext.request.contextPath }/js/plugins/sweetalert/sweetalert.min.js"></script>
	
    <!-- Page-Level Scripts -->
    
    
    <script>
  
    function addWebSite(){
    	var config_name=$("#config_name").val();
		var url=$("#url").val();
		var search_rule=$("#search_rule").val();
		var url_config=$("#url_config").val();
		var title_config=$("#title_config").val();
		var date_config=$("#date_config").val();
		var text_config=$("#text_config").val();
		var text_config_type=$("#text_config_type").val();
		var spider_type=$("#spider_type").val();
		var request_type=$("#request_type").val();
		var website_id=$("#ipt").val();
		var isOnSite=$("#isOnSite").val();
		var request_config=$("#request_config").val();
		var result_type=$("#result_type").val();
		var id = '${id}';
		var pageNum = '${pageNum}';
		if($("#config_name").val()==null||$("#config_name").val()=="")
    	{
    		toastr.error('请输入配置名')
    		return;
    	}else if($("#url").val()==null||$("#url").val()=="")
    	{
    		toastr.error('请输入搜索页链接')
    		return;
    	}else if($("#search_rule").val()==null||$("#search_rule").val()==""){
    		toastr.error('请输入搜索链接配置')
    		return;
    	}else if($("#url_config").val()==null||$("#url_config").val()==""){
    		toastr.error('请输入url提取规则')
    		return;
    	}else if(spider_type!="1"){
    		if($("#title_config").val()==null||$("#title_config").val()==""){
        		toastr.error('请输入标题提取规则')
        		return;
        	}else if($("#date_config").val()==null||$("#date_config").val()==""){
        		toastr.error('请输入日期提取规则')
        		return;
        	}else if($("#text_config").val()==null||$("#text_config").val()==""){
        		toastr.error('请输入正文提取规则')
        		return;
        	}
    	}else if($("#spider_type").val()==null||$("#spider_type").val()==""){
    		toastr.error('请选择提取方式')
    		return;
    	}else if($("#request_type").val()==null||$("#request_type").val()==""){
    		toastr.error('请选择请求方式')
    		return;
    	}else if($("#ipt").val()==null||$("#ipt").val()==""){
    		toastr.error('请输入对应网站id')
    		return;
    	}else if($("#isOnSite").val()==null||$("#isOnSite").val()==""){
    		toastr.error('请选择是否站内搜索')
    		return;
    	}else if($("#result_type").val()==null||$("#result_type").val()==""){
    		toastr.error('请选择返回类型')
    		return;
    	}
    	swal({
            title: "确定编辑该配置?",
//          text: "Your will not be able to recover this imaginary file!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false,
            closeOnCancel: true },
        function (isConfirm) {
            if (isConfirm) {
            	
                $.ajax({
            		url : "${pageContext.request.contextPath}/allocation/editor?id="+id,
            		type : "post",
            		data : {
            			config_name:config_name,
            			url:url,
            			search_rule:search_rule,
            			url_config:url_config,
            			title_config:title_config,
            			date_config:date_config,
            			text_config:text_config,
            			text_config_type:text_config_type,
            			spider_type:spider_type,
            			request_type:request_type,
            			website_id:website_id,
            			isOnSite:isOnSite,
            			request_config:request_config,
            			result_type:result_type
            		},
            		success : function(data) {
            			if(data.code==1){
            				swal("编辑成功", "该配置编辑成功", "success");
            				window.location.href = "${pageContext.request.contextPath}/searchenging/configlist?pageNum="+pageNum
            			}
            		},
            		error : function(e) {
            			swal("编辑失败", "编辑失败", "error");
            			window.clearInterval(timer);
            		}
            	});
            }else{
            	
            } 
        });
    	
    	
    }
    
    
  //跑马灯方法 
// 	 function init(){
// 		    //获取标题
// 		    var title=document.title;
// 		    //分割字符串--->字符数组
// 		    var arr=title.split("");
// 		    //删除第一个元素并返回该元素
// 		    var e=arr.shift();
// 		    //把一个对象添加到数组末尾
// 		    arr.push(e);
// 		    //把数组转换成字符串
// 		    var marquee=arr.join("");
// 		    //返回给浏览器
// 		    document.title=marquee;
// 		    //定时一直执行
// 		    window.setTimeout("init()",1000);
// 		}
// 		window.onload=init;
	 
    
    </script>

</body>

</html>
